<template>
  <views class="employee_list">
    <viewTitle :title="'从业人员列表'"></viewTitle>
    <div class="search">
      <el-form ref="form" label-width="auto" :inline="true">
        <el-form-item label="姓名:">
          <el-input type="text" clearable placeholder="请输入姓名" v-model="employee_name"></el-input>
        </el-form-item>
        <el-form-item label="在职状态:">
          <el-select v-model="status" clearable placeholder="请选择">
            <el-option
                    v-for="item in status_list"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="企业名称:">
          <el-input type="text" clearable placeholder="请输入企业名称" v-model="company_name"></el-input>
        </el-form-item>
        <el-form-item label="企业类型:">
          <el-select v-model="company_type" clearable placeholder="请选择">
            <el-option
                    v-for="item in company_type_list"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="联系电话:">
          <el-input type="text" clearable placeholder="请输入联系电话" v-model="employee_mobile"></el-input>
        </el-form-item>
        <el-form-item label="身份证号:">
          <el-input type="text" clearable placeholder="请输入身份证号" v-model="card_no"></el-input>
        </el-form-item>
        <el-form-item label="入职时间:">
          <el-date-picker
                  v-model="registration_date"
                  type="datetimerange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"

          ></el-date-picker>
        </el-form-item>
      </el-form>
      <div class="btn-area">
        <el-button type="primary" @click="getData">查询</el-button>
        <el-button @click="reset">重置</el-button>
      </div>
    </div>
    <div class="table_list">
      <el-table :data="tableList" style="width: 100%" border :header-cell-style="getRowClass">
        <el-table-column type="index" label="序号" width="100"></el-table-column>
        <el-table-column prop="employee_name" label="人员姓名" width="180"></el-table-column>
        <el-table-column prop="employee_mobile" label="联系电话" width="180"></el-table-column>
        <el-table-column prop="company_name" label="企业名称" width="180"></el-table-column>
        <el-table-column :formatter="(row)=>{ return row.type == 1 ? '快递':'物流'}" label="企业类型" width="180"></el-table-column>
        <el-table-column prop="profession_desc" label="职业对象" width="180"></el-table-column>
        <el-table-column prop="create_time" label="入职时间" width="180"></el-table-column>
        <el-table-column prop="card_no" label="身份证号" width="auto"></el-table-column>
        <el-table-column :formatter="(row)=>{ return row.status == 1 ? '在职':'离职'}" label="在职状态" width="180"></el-table-column>
        <el-table-column fixed="right" label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="success" v-if="$route.query.check.q" @click="toDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="flex flexR paging">
        <el-pagination
          style="background:#fff; padding:10px 0"
          background
          layout="prev, pager, next,sizes,total, jumper"
          @size-change="(page_size) => {this.pagination.page_size = page_size;this.getData()}"
          @current-change="(page_size) => {this.pagination.page_start = page_size;this.getData()}"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pagination.page_size"
          :total="pagination.total_count"
          :current-page="pagination.current_page"
          :page-count="pagination.page_count"
        ></el-pagination>
      </div>
    </div>
  </views>
</template>


<script>
export default {
  data() {
    return {
      employee_name: "", // 员工姓名
      employee_mobile: "", // 联系电话
      status: "", //在职状态
      company_name: "", //企业名称
      company_id:"",
      checktype:"",
      card_no:"",//身份证号
      status_list: [
        {
          value: "",
          label: "全部"
        },
        {
            value: "1",
            label: "在职"
        },
        {
            value: "2",
            label: "离职"
        }
      ],
        // 组织列表
      tableList: [
      ],
      pagination: {
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      },
      company_type: null,
      company_type_list: [
        {value:null, label:'全部'},
        {value:0, label:'物流'},
        {value:1, label:'快递'}
      ],
      registration_date: [], // 注册时间
    };
  },
  methods: {
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    //    修改是否换行
    changeStyleRow(width) {
      let _width = width - 290 - 350 - 300 - 50 - 25;
      if (_width > 300) {
        this.marginLeft = 25;
      } else {
        this.marginLeft = 0;
      }
    },
    // 获取数据
    getData() {
           this.$raxios.post(
            this.$mapapi.admin_employeeList,{
             data:this.post_data
            }).then(res=>{
              if(res.code==200){
              this.tableList = res.data.list;
              this.pagination = res.data.pagination;
              }else{
              this.tableList = [];
              this.pagination = [];
	              this.$message.error(res.msg)
              return;
              }
            }).catch(res=>{

            })   
    },
      getdata() {
      this.$raxios.post(
            this.$mapapi.admin_employeeList,
            {
             data:this.post_dataS
            }
        ).then(res=>{
              if(res.code==200){
              this.tableList = res.data.list;
              this.pagination = res.data.pagination;
              }else{
              this.tableList = [];
              this.pagination = [];
	              this.$message.error(res.msg)
              return;
              }
            }).catch(res=>{

            })   
    },
    // 去详情
    toDetail(row) {
      this.$toRoutePath({
        path: "/employee_list/employee_list_detail",
        edit: true,
        query: { type: 1 ,employee_id:row.employee_id}
      });
    },
    // 重置
    reset() {
        this.employee_name = '';
        this.employee_mobile = '';
        this.status = '';
        this.company_name = '';
        this.card_no = '';
        this.company_type = null;
        this.registration_date = [];
        this.getData();
    }
  },
  computed:{
      post_data(){
          let data = {};
          data.employee_name = this.employee_name;
          data.employee_mobile = this.employee_mobile;
          data.status = this.status;
          data.company_name = this.company_name;
          data.card_no = this.card_no;
          data.pagination = this.pagination;
          data.company_id= this.company_id 
        if(this.registration_date.length > 0){
          data.start_created_time = this.registration_date[0]/1000;     //开始时间
          data.end_created_time = this.registration_date[1]/1000;     //结束时间
        }
        data.type = this.company_type;
          return data
      },
       post_dataS(){
          let data = {};
          data.employee_name = this.employee_name;
          data.employee_mobile = this.employee_mobile;
          data.status = this.status;
          data.company_name = this.company_name;
          data.card_no = this.card_no;
          data.pagination = this.pagination;
          data.company_id= this.company_id 
        if(this.registration_date.length > 0){
          data.start_created_time = this.registration_date[0]/1000;     //开始时间
          data.end_created_time = this.registration_date[1]/1000;     //结束时间
        }
        data.type = this.company_type;
          return data
      }
    
  },
  mounted() {
      if(this.checktype === 1){
       this.getdata()
      }else{
        this.getData()
      }
  },
  created() {
    this.checktype = this.$route.query.checktype;
    this.company_id = this.$route.query.company_id;
    this.company_id && this.getData();
  }
};
</script>
<style lang="less" :scope="true"  src="@/style/personnel_manager/employee_list.less">
</style>
